package com.cz.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {

    final String CREATE_TABLE_FRIEND =
            "create table friends" +
            "(uid varchar(17) NOT NULL PRIMARY KEY," +
            "nickname varchar(25)," +
            "remark varchar(25)," +
            "phone varchar(11)," +
            "avatar varchar(32)," +
            "address varchar(25))";

    final String CREATE_TABLE_CHATRECORD =
            "create table chatrecords" +
            "(rid int NOT NULL PRIMARY KEY," +
            "message varchar(255)," +
            "userid varchar(17)," +
            "ismyself int," +
            "msgtime datetime)";

    final String CREATE_TABLE_DIALOGUELIST=
            "create table dialoguelist" +
            "(listid int NOT NULL PRIMARY KEY," +
            "endmessage varchar(25)," +
            "userid varchar(17)," +
            "headimg varchar(32)," +
            "endtime datetime)";

    final String CREATE_TABLE_MINE =
            "create table mine" +
            "(userid varchar(17) NOT NULL PRIMARY KEY," +
            "password varchar(25)," +
            "nickname varchar(25)," +
            "phone varchar(11)," +
            "headimg varchar(32)," +
            "address varchar(25))";


    public DBOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, null, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_FRIEND);
        db.execSQL(CREATE_TABLE_CHATRECORD);
        db.execSQL(CREATE_TABLE_DIALOGUELIST);
        db.execSQL(CREATE_TABLE_MINE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.e("数据库升级","旧版本 : " + oldVersion +"更新版本 : " + newVersion);
    }
}
